package me.zhengjie.minbearwcs.dao.outbound.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.outbound.inf.OutboundTaskRecordDao;
import me.zhengjie.minbearwcs.entity.Mapper.outbound.OutboundTaskRecordMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.outbound.record.OutboundTaskRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class OutboundTaskRecordDaoImpl implements OutboundTaskRecordDao {

    private final OutboundTaskRecordMapper mapper;


    @Override
    public boolean insert(OutboundTaskRecord outboundTaskRecord) {
        return mapper.insert(outboundTaskRecord) == 1;
    }

    @Override
    public OutboundTaskRecord selectByOutboundRecordId(String recordId) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getOutboundRecordId, recordId)
                .one();
    }

    @Override
    public boolean updateDestinationInfoByRecordId(String recordId, Integer destinationFloorNum, String destinationStorage) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getOutboundRecordId, recordId)
                .set(OutboundTaskRecord::getDestinationFloorNum, destinationFloorNum)
                .set(OutboundTaskRecord::getDestinationSmallStorage, destinationStorage)
                .update();
    }

    @Override
    public boolean update(OutboundTaskRecord outboundTaskRecord) {
        return mapper.updateById(outboundTaskRecord) == 1;
    }

    @Override
    public List<OutboundTaskRecord> selectSortPalletByPalletCode(String palletCode, Integer isSort) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getPalletCode, palletCode)
                .eq(OutboundTaskRecord::getIsSort, isSort)
                .list();
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) == 1;
    }

    @Override
    public OutboundTaskRecord selectByPalletAndDestinationStorage(String pallet, String destinationSmallStorage) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getPalletCode, pallet)
                .eq(OutboundTaskRecord::getDestinationSmallStorage, destinationSmallStorage)
                .one();
    }

    @Override
    public List<OutboundTaskRecord> selectByOutboundOrderCode(String outobundOrderCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getOutboundOrderCode, outobundOrderCode)
                .list();
    }

    @Override
    public boolean updateDestinationStorageByRecordId(String recordId, String destinationStorage) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(OutboundTaskRecord::getOutboundRecordId, recordId)
                .set(OutboundTaskRecord::getDestinationSmallStorage, destinationStorage)
                .update();
    }
}
